package edu.zut.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "SessionDemo2", value = "/session/demo2")
public class SessionDemo2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取session保存数据
        HttpSession session = request.getSession();
        //保存数据
        session.setAttribute("myName","xueyin");
        session.setAttribute("myAge",20);
        //获取数据
        Object myName = session.getAttribute("myName");
        System.out.println("myName = " + myName);
        //修改数据
        session.setAttribute("myName","xuexiaoyin");

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
